﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KendoMvcUI.Core;
using KendoMvcUI.Common;

namespace KendoMvcUI.UI
{
    public class ToolBarItemSettings : KendoUIControlSettings
    {
        public ToolBarItemSettings()
            : base("")
        { }
        /// <summary>
        /// Specifies the HTML attributes of a ToolBar button.
        /// </summary>
        public object Attributes { get; set; }
        /// <summary>
        /// Specifies the buttons of ButtonGroup.
        /// </summary>
        [PropertySetting(IsIngoreForJavaScript=true)]
        public Action<List<ToolBarItemButtonSettings>> Buttons { get; set; }
        private string jsString = "";
        public string Click { get; set; }
        public bool? Enable { get; set; }
        public string Group { get; set; }
        public string Icon { get; set; }
        public string ImageUrl { get; set; }
        [PropertySetting(IsIngoreForJavaScript=true)]
        public Action<List<ToolBarItemMenuButtonSettings>> MenuButtons { get; set; }
        /// <summary>
        /// Specifies how the button behaves when the ToolBar is resized. 
        /// Possible values are: "always", "never" or "auto" (default).
        /// </summary>
        public string Overflow { get; set; }
        public string OverflowTemplate { get; set; }
        public bool? Primary { get; set; }
        public bool? Selected { get; set; }
        /// <summary>
        /// Specifies where the button icon will be displayed. 
        /// Possible values are: "toolbar", "overflow" or "both" (default).
        /// </summary>
        public string ShowIcon { get; set; }
        /// <summary>
        /// Specifies where the text will be displayed. 
        /// Possible values are: "toolbar", "overflow" or "both" (default).
        /// </summary>
        public string ShowText { get; set; }
        public string SpriteCssClass { get; set; }
        /// <summary>
        /// Specifies what element will be added in the ToolBar wrapper. Items with template does not have a type.
        /// If overflowTemplate is not defined for a template command, 
        /// than the command will be threated as overflow: "never".
        /// </summary>
        public string Template { get; set; }
        public string Text { get; set; }
        /// <summary>
        /// Buttons with togglable: true will fire the toggle event. click event will not be fired.
        /// </summary>
        public bool? Togglable { get; set; }
        public string Toggle { get; set; }
        /// <summary>
        /// Specifies the command type. Supported types are "button", "splitButton", "buttonGroup", "separator".
        /// </summary>
        public string Type { get; set; }
        public string Url { get; set; }

        public override string ToJsSettings()
        {
            var js=base.ToJsSettings();
            if(Buttons!=null)
            {
                string btnJs = "";
                List<ToolBarItemButtonSettings> buttons = new List<ToolBarItemButtonSettings>();
                Buttons(buttons);
                buttons.ForEach(s => {
                    btnJs += "{" + s.ToString() + "},";
                });
                js += "buttons:[{0}],".Formator(btnJs.TrimEnd(','));
            }
            if(MenuButtons!=null)
            {
                string menuBtnJs = "";
                List<ToolBarItemMenuButtonSettings> menuBtns = new List<ToolBarItemMenuButtonSettings>();
                MenuButtons(menuBtns);
                menuBtns.ForEach(b =>
                {
                    menuBtnJs += "{" + b.ToString() + "},";
                });
                js += "menuButtons:[{0}],".Formator(menuBtnJs.TrimEnd(','));
            }

            return js.TrimEnd(',');
        }
    }
    public class ToolBarItemButtonSettings
    {
        public ToolBarItemButtonSettings()
        { }
        /// <summary>
        /// Specifies the HTML attributes of a ButtonGroup's button.
        /// HTML attributes which are JavaScript keywords (e.g. class) must be quoted.
        /// </summary>
        public object Attributes { get; set; }
        /// <summary>
        /// Specifies the click event handler of the button. Applicable only for the children of a ButtonGroup.
        /// </summary>
        public string Click { get; set; }
        public bool? Enable { get; set; }
        public string Group { get; set; }
        public string Icon { get; set; }
        public string ImageUrl { get; set; }
        public string Id { get; set; }
        public string Selected { get; set; }
        /// <summary>
        /// Specifies where the icon of the button will be displayed
        /// default: "both"
        /// </summary>
        public string ShowIcon { get; set; }
        public string ShowText { get; set; }
        /// <summary>
        /// Defines a CSS class (or multiple classes separated by spaces) which will be used for button icon.
        /// </summary>
        public string SpriteCssClass { get; set; }
        /// <summary>
        /// Specifies the toggle event handler of the button. Applicable only for the children of a ButtonGroup.
        /// </summary>
        public string Toggle { get; set; }
        public bool? Togglable { get; set; }
        public string Text { get; set; }
        public string Url { get; set; }
        public override string ToString()
        {
            return SettingsEx.ToJSSettings(this);
        }
    }

    public class ToolBarItemMenuButtonSettings 
    {
        public ToolBarItemMenuButtonSettings()
        { }
        /// <summary>
        /// Specifies the HTML attributes of a ButtonGroup's button.
        /// HTML attributes which are JavaScript keywords (e.g. class) must be quoted.
        /// </summary>
        public object Attributes { get; set; }

        public bool? Enable { get; set; }
        public string Icon { get; set; }
        public string ImageUrl { get; set; }
        public string Id { get; set; }
        /// <summary>
        /// Defines a CSS class (or multiple classes separated by spaces) which will be used for button icon.
        /// </summary>
        public string SpriteCssClass { get; set; }
        public string Text { get; set; }
        public string Url { get; set; }
        public override string ToString()
        {
            return SettingsEx.ToJSSettings(this);
        }
    }
}
